<? include 'dbcommon.php'; ?>
<?

class danhmuc {

    public $id;
    public $ten;
    public $noidung;
    public $isdeleted;

}

class danhmucdb {

    public static function insert(&$entity) {
        $db = new dbhelper();
        $query = "  INSERT INTO DanhMuc ( Ten , NoiDung ,  IsDeleted) VALUES ( #Ten#, #NoiDung#, #IsDeleted#)";
        $db->setQuery($query);
        $db->set_string_params("Ten", $entity->ten);
        $db->set_string_params("NoiDung", $entity->noidung);
        $db->set_string_params("IsDeleted", $entity->isdeleted);
        return $db->excute();
    }

    public static function update(&$entity) {
        $db = new dbhelper();
        $query = "UPDATE DanhMuc SET Ten = #Ten#, NoiDung = #NoiDung#, IsDeleted = #IsDeleted# WHERE Id = #Id#";
        $db->setQuery($query);
        $db->set_string_params("Id", $entity->id);
        $db->set_string_params("Ten", $entity->ten);
        $db->set_string_params("NoiDung", $entity->noidung);
        $db->set_string_params("IsDeleted", $entity->isdeleted);
        return $db->excute();
    }

    public static function get_all() {
        $db = new dbhelper();
        $query = "SELECT * FROM DanhMuc";
        $db->setQuery($query);
        $result = $db->excute();
        $entity_arr = array();
        $index = 0;
        while ($row = mysql_fetch_array($result)) {
            $entity = new danhmuc();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->noidung = $row['NoiDung'];
            $entity->isdeleted = $row['IsDeleted'];
            $entity_arr[$index] = $entity;
            $index = $index + 1;
        }
        return $entity_arr;
    }

    public static function get(&$entity) {
        $db = new dbhelper();
        $query = "SELECT * FROM DanhMuc WHERE Id = #Id#";
        $db->setQuery($query);
        $db->set_string_params("Id", $entity->id);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new danhmuc();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->noidung = $row['NoiDung'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_id($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM DanhMuc WHERE id = #id#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new danhmuc();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->noidung = $row['NoiDung'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_ten($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM DanhMuc WHERE ten = #ten#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new danhmuc();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->noidung = $row['NoiDung'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_noidung($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM DanhMuc WHERE noidung = #noidung#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new danhmuc();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->noidung = $row['NoiDung'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_isdeleted($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM DanhMuc WHERE isdeleted = #isdeleted#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new danhmuc();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->noidung = $row['NoiDung'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_post_data() {
        $entity = new danhmuc();
        $entity->id = $_POST["id"];
        $entity->ten = $_POST["ten"];
        $entity->noidung = $_POST["noidung"];
        $entity->isdeleted = $_POST["isdeleted"];
        return $entity;
    }

    public static function search($search_key) {
        $arr = explode(" ", trim($search_key));
        $search = "";
        for ($i = 0; $i < count($arr); $i++) {
            if ($search == "") {
                $search = $search . " WHERE ";
                $search = $search . "(";
                $search = $search . "id LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || ten LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || noidung LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || isdeleted LIKE '%" . $arr[$i] . "%'";
                $search = $search . ")";
            } else {
                $search = $search . " AND ";
                $search = $search . "(";
                $search = $search . "id LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || ten LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || noidung LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || isdeleted LIKE '%" . $arr[$i] . "%'";
                $search = $search . ")";
            }
            $db = new dbhelper();
            $query = "SELECT * FROM DanhMuc" . $search;
            $db->setQuery($query);
            $result = $db->excute();
            $entity_arr = array();
            $index = 0;
            while ($row = mysql_fetch_array($result)) {
                $entity = new danhmuc();
                $entity->id = $row['Id'];
                $entity->ten = $row['Ten'];
                $entity->noidung = $row['NoiDung'];
                $entity->isdeleted = $row['IsDeleted'];
                $entity_arr[$index] = $entity;
                $index = $index + 1;
            }
            return $entity_arr;
        }
    }

}

?><?

class donhang {

    public $id;
    public $ngaythang;
    public $tenkhachhang;
    public $diachi;
    public $sodienthoai;
    public $tonghoadon;
    public $isdeleted;

}

class donhangdb {

    public static function insert(&$entity) {
        $db = new dbhelper();
        $query = "     INSERT INTO DonHang ( NgayThang , TenKhachHang , DiaChi , SoDienThoai , TongHoaDon ,  IsDeleted) VALUES ( #NgayThang#, #TenKhachHang#, #DiaChi#, #SoDienThoai#, #TongHoaDon#, #IsDeleted#)";
        $db->setQuery($query);
        $db->set_string_params("NgayThang", $entity->ngaythang);
        $db->set_string_params("TenKhachHang", $entity->tenkhachhang);
        $db->set_string_params("DiaChi", $entity->diachi);
        $db->set_string_params("SoDienThoai", $entity->sodienthoai);
        $db->set_string_params("TongHoaDon", $entity->tonghoadon);
        $db->set_string_params("IsDeleted", $entity->isdeleted);
        return $db->excute();
    }

    public static function update(&$entity) {
        $db = new dbhelper();
        $query = "UPDATE DonHang SET NgayThang = #NgayThang#, TenKhachHang = #TenKhachHang#, DiaChi = #DiaChi#, SoDienThoai = #SoDienThoai#, TongHoaDon = #TongHoaDon#, IsDeleted = #IsDeleted# WHERE Id = #Id#";
        $db->setQuery($query);
        $db->set_string_params("Id", $entity->id);
        $db->set_string_params("NgayThang", $entity->ngaythang);
        $db->set_string_params("TenKhachHang", $entity->tenkhachhang);
        $db->set_string_params("DiaChi", $entity->diachi);
        $db->set_string_params("SoDienThoai", $entity->sodienthoai);
        $db->set_string_params("TongHoaDon", $entity->tonghoadon);
        $db->set_string_params("IsDeleted", $entity->isdeleted);
        return $db->excute();
    }

    public static function get_all() {
        $db = new dbhelper();
        $query = "SELECT * FROM DonHang";
        $db->setQuery($query);
        $result = $db->excute();
        $entity_arr = array();
        $index = 0;
        while ($row = mysql_fetch_array($result)) {
            $entity = new donhang();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->tonghoadon = $row['TongHoaDon'];
            $entity->isdeleted = $row['IsDeleted'];
            $entity_arr[$index] = $entity;
            $index = $index + 1;
        }
        return $entity_arr;
    }

    public static function get(&$entity) {
        $db = new dbhelper();
        $query = "SELECT * FROM DonHang WHERE Id = #Id#";
        $db->setQuery($query);
        $db->set_string_params("Id", $entity->id);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new donhang();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->tonghoadon = $row['TongHoaDon'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_id($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM DonHang WHERE id = #id#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new donhang();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->tonghoadon = $row['TongHoaDon'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_ngaythang($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM DonHang WHERE ngaythang = #ngaythang#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new donhang();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->tonghoadon = $row['TongHoaDon'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_tenkhachhang($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM DonHang WHERE tenkhachhang = #tenkhachhang#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new donhang();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->tonghoadon = $row['TongHoaDon'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_diachi($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM DonHang WHERE diachi = #diachi#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new donhang();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->tonghoadon = $row['TongHoaDon'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_sodienthoai($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM DonHang WHERE sodienthoai = #sodienthoai#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new donhang();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->tonghoadon = $row['TongHoaDon'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_tonghoadon($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM DonHang WHERE tonghoadon = #tonghoadon#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new donhang();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->tonghoadon = $row['TongHoaDon'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_isdeleted($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM DonHang WHERE isdeleted = #isdeleted#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new donhang();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->tonghoadon = $row['TongHoaDon'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_post_data() {
        $entity = new donhang();
        $entity->id = $_POST["id"];
        $entity->ngaythang = $_POST["ngaythang"];
        $entity->tenkhachhang = $_POST["tenkhachhang"];
        $entity->diachi = $_POST["diachi"];
        $entity->sodienthoai = $_POST["sodienthoai"];
        $entity->tonghoadon = $_POST["tonghoadon"];
        $entity->isdeleted = $_POST["isdeleted"];
        return $entity;
    }

    public static function search($search_key) {
        $arr = explode(" ", trim($search_key));
        $search = "";
        for ($i = 0; $i < count($arr); $i++) {
            if ($search == "") {
                $search = $search . " WHERE ";
                $search = $search . "(";
                $search = $search . "id LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || ngaythang LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || tenkhachhang LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || diachi LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || sodienthoai LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || tonghoadon LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || isdeleted LIKE '%" . $arr[$i] . "%'";
                $search = $search . ")";
            } else {
                $search = $search . " AND ";
                $search = $search . "(";
                $search = $search . "id LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || ngaythang LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || tenkhachhang LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || diachi LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || sodienthoai LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || tonghoadon LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || isdeleted LIKE '%" . $arr[$i] . "%'";
                $search = $search . ")";
            }
            $db = new dbhelper();
            $query = "SELECT * FROM DonHang" . $search;
            $db->setQuery($query);
            $result = $db->excute();
            $entity_arr = array();
            $index = 0;
            while ($row = mysql_fetch_array($result)) {
                $entity = new donhang();
                $entity->id = $row['Id'];
                $entity->ngaythang = $row['NgayThang'];
                $entity->tenkhachhang = $row['TenKhachHang'];
                $entity->diachi = $row['DiaChi'];
                $entity->sodienthoai = $row['SoDienThoai'];
                $entity->tonghoadon = $row['TongHoaDon'];
                $entity->isdeleted = $row['IsDeleted'];
                $entity_arr[$index] = $entity;
                $index = $index + 1;
            }
            return $entity_arr;
        }
    }

}

?><?

class donhangchitiet {

    public $id;
    public $donhangid;
    public $sanphamid;
    public $soluong;

}

class donhangchitietdb {

    public static function insert(&$entity) {
        $db = new dbhelper();
        $query = "   INSERT INTO DonHangChiTiet ( Id , DonHangID , SanPhamID ,  SoLuong) VALUES ( #Id#, #DonHangID#, #SanPhamID#, #SoLuong#)";
        $db->setQuery($query);
        $db->set_string_params("Id", $entity->id);
        $db->set_string_params("DonHangID", $entity->donhangid);
        $db->set_string_params("SanPhamID", $entity->sanphamid);
        $db->set_string_params("SoLuong", $entity->soluong);
        return $db->excute();
    }

    public static function update(&$entity) {
        $db = new dbhelper();
        $query = "UPDATE DonHangChiTiet SET Id = #Id#, DonHangID = #DonHangID#, SanPhamID = #SanPhamID#, SoLuong = #SoLuong# WHERE ";
        $db->setQuery($query);
        $db->set_string_params("Id", $entity->id);
        $db->set_string_params("DonHangID", $entity->donhangid);
        $db->set_string_params("SanPhamID", $entity->sanphamid);
        $db->set_string_params("SoLuong", $entity->soluong);
        return $db->excute();
    }

    public static function get_all() {
        $db = new dbhelper();
        $query = "SELECT * FROM DonHangChiTiet";
        $db->setQuery($query);
        $result = $db->excute();
        $entity_arr = array();
        $index = 0;
        while ($row = mysql_fetch_array($result)) {
            $entity = new donhangchitiet();
            $entity->id = $row['Id'];
            $entity->donhangid = $row['DonHangID'];
            $entity->sanphamid = $row['SanPhamID'];
            $entity->soluong = $row['SoLuong'];
            $entity_arr[$index] = $entity;
            $index = $index + 1;
        }
        return $entity_arr;
    }

    public static function get(&$entity) {
        $db = new dbhelper();
        $query = "SELECT * FROM DonHangChiTiet WHERE Id = #Id#";
        $db->setQuery($query);
        $db->set_string_params("Id", $entity->id);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new donhangchitiet();
            $entity->id = $row['Id'];
            $entity->donhangid = $row['DonHangID'];
            $entity->sanphamid = $row['SanPhamID'];
            $entity->soluong = $row['SoLuong'];
            return $entity;
        }
    }

    public static function get_by_id($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM DonHangChiTiet WHERE id = #id#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new donhangchitiet();
            $entity->id = $row['Id'];
            $entity->donhangid = $row['DonHangID'];
            $entity->sanphamid = $row['SanPhamID'];
            $entity->soluong = $row['SoLuong'];
            return $entity;
        }
    }

    public static function get_by_donhangid($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM DonHangChiTiet WHERE donhangid = #donhangid#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new donhangchitiet();
            $entity->id = $row['Id'];
            $entity->donhangid = $row['DonHangID'];
            $entity->sanphamid = $row['SanPhamID'];
            $entity->soluong = $row['SoLuong'];
            return $entity;
        }
    }

    public static function get_by_sanphamid($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM DonHangChiTiet WHERE sanphamid = #sanphamid#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new donhangchitiet();
            $entity->id = $row['Id'];
            $entity->donhangid = $row['DonHangID'];
            $entity->sanphamid = $row['SanPhamID'];
            $entity->soluong = $row['SoLuong'];
            return $entity;
        }
    }

    public static function get_by_soluong($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM DonHangChiTiet WHERE soluong = #soluong#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new donhangchitiet();
            $entity->id = $row['Id'];
            $entity->donhangid = $row['DonHangID'];
            $entity->sanphamid = $row['SanPhamID'];
            $entity->soluong = $row['SoLuong'];
            return $entity;
        }
    }

    public static function get_post_data() {
        $entity = new donhangchitiet();
        $entity->id = $_POST["id"];
        $entity->donhangid = $_POST["donhangid"];
        $entity->sanphamid = $_POST["sanphamid"];
        $entity->soluong = $_POST["soluong"];
        return $entity;
    }

    public static function search($search_key) {
        $arr = explode(" ", trim($search_key));
        $search = "";
        for ($i = 0; $i < count($arr); $i++) {
            if ($search == "") {
                $search = $search . " WHERE ";
                $search = $search . "(";
                $search = $search . "id LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || donhangid LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || sanphamid LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || soluong LIKE '%" . $arr[$i] . "%'";
                $search = $search . ")";
            } else {
                $search = $search . " AND ";
                $search = $search . "(";
                $search = $search . "id LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || donhangid LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || sanphamid LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || soluong LIKE '%" . $arr[$i] . "%'";
                $search = $search . ")";
            }
            $db = new dbhelper();
            $query = "SELECT * FROM DonHangChiTiet" . $search;
            $db->setQuery($query);
            $result = $db->excute();
            $entity_arr = array();
            $index = 0;
            while ($row = mysql_fetch_array($result)) {
                $entity = new donhangchitiet();
                $entity->id = $row['Id'];
                $entity->donhangid = $row['DonHangID'];
                $entity->sanphamid = $row['SanPhamID'];
                $entity->soluong = $row['SoLuong'];
                $entity_arr[$index] = $entity;
                $index = $index + 1;
            }
            return $entity_arr;
        }
    }

}

?><?

class loaisanpham {

    public $id;
    public $ten;
    public $isdeleted;

}

class loaisanphamdb {

    public static function insert(&$entity) {
        $db = new dbhelper();
        $query = " INSERT INTO LoaiSanPham ( Ten ,  IsDeleted) VALUES ( #Ten#, #IsDeleted#)";
        $db->setQuery($query);
        $db->set_string_params("Ten", $entity->ten);
        $db->set_string_params("IsDeleted", $entity->isdeleted);
        return $db->excute();
    }

    public static function update(&$entity) {
        $db = new dbhelper();
        $query = "UPDATE LoaiSanPham SET Ten = #Ten#, IsDeleted = #IsDeleted# WHERE Id = #Id#";
        $db->setQuery($query);
        $db->set_string_params("Id", $entity->id);
        $db->set_string_params("Ten", $entity->ten);
        $db->set_string_params("IsDeleted", $entity->isdeleted);
        return $db->excute();
    }

    public static function get_all() {
        $db = new dbhelper();
        $query = "SELECT * FROM LoaiSanPham";
        $db->setQuery($query);
        $result = $db->excute();
        $entity_arr = array();
        $index = 0;
        while ($row = mysql_fetch_array($result)) {
            $entity = new loaisanpham();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->isdeleted = $row['IsDeleted'];
            $entity_arr[$index] = $entity;
            $index = $index + 1;
        }
        return $entity_arr;
    }

    public static function get(&$entity) {
        $db = new dbhelper();
        $query = "SELECT * FROM LoaiSanPham WHERE Id = #Id#";
        $db->setQuery($query);
        $db->set_string_params("Id", $entity->id);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new loaisanpham();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_id($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM LoaiSanPham WHERE id = #id#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new loaisanpham();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_ten($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM LoaiSanPham WHERE ten = #ten#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new loaisanpham();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_isdeleted($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM LoaiSanPham WHERE isdeleted = #isdeleted#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new loaisanpham();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_post_data() {
        $entity = new loaisanpham();
        $entity->id = $_POST["id"];
        $entity->ten = $_POST["ten"];
        $entity->isdeleted = $_POST["isdeleted"];
        return $entity;
    }

    public static function search($search_key) {
        $arr = explode(" ", trim($search_key));
        $search = "";
        for ($i = 0; $i < count($arr); $i++) {
            if ($search == "") {
                $search = $search . " WHERE ";
                $search = $search . "(";
                $search = $search . "id LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || ten LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || isdeleted LIKE '%" . $arr[$i] . "%'";
                $search = $search . ")";
            } else {
                $search = $search . " AND ";
                $search = $search . "(";
                $search = $search . "id LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || ten LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || isdeleted LIKE '%" . $arr[$i] . "%'";
                $search = $search . ")";
            }
            $db = new dbhelper();
            $query = "SELECT * FROM LoaiSanPham" . $search;
            $db->setQuery($query);
            $result = $db->excute();
            $entity_arr = array();
            $index = 0;
            while ($row = mysql_fetch_array($result)) {
                $entity = new loaisanpham();
                $entity->id = $row['Id'];
                $entity->ten = $row['Ten'];
                $entity->isdeleted = $row['IsDeleted'];
                $entity_arr[$index] = $entity;
                $index = $index + 1;
            }
            return $entity_arr;
        }
    }

}

?><?

class sanpham {

    public $id;
    public $ten;
    public $gia;
    public $loaisanpham;
    public $hinhanh;
    public $thongtin;
    public $isdeleted;

}

class sanphamdb {

    public static function insert(&$entity) {
        $db = new dbhelper();
        $query = "     INSERT INTO SanPham ( Ten , Gia , LoaiSanPham , HinhAnh , ThongTin ,  IsDeleted) VALUES ( #Ten#, #Gia#, #LoaiSanPham#, #HinhAnh#, #ThongTin#, #IsDeleted#)";
        $db->setQuery($query);
        $db->set_string_params("Ten", $entity->ten);
        $db->set_string_params("Gia", $entity->gia);
        $db->set_string_params("LoaiSanPham", $entity->loaisanpham);
        $db->set_string_params("HinhAnh", $entity->hinhanh);
        $db->set_string_params("ThongTin", $entity->thongtin);
        $db->set_string_params("IsDeleted", $entity->isdeleted);
        return $db->excute();
    }

    public static function update(&$entity) {
        $db = new dbhelper();
        $query = "UPDATE SanPham SET Ten = #Ten#, Gia = #Gia#, LoaiSanPham = #LoaiSanPham#, HinhAnh = #HinhAnh#, ThongTin = #ThongTin#, IsDeleted = #IsDeleted# WHERE Id = #Id#";
        $db->setQuery($query);
        $db->set_string_params("Id", $entity->id);
        $db->set_string_params("Ten", $entity->ten);
        $db->set_string_params("Gia", $entity->gia);
        $db->set_string_params("LoaiSanPham", $entity->loaisanpham);
        $db->set_string_params("HinhAnh", $entity->hinhanh);
        $db->set_string_params("ThongTin", $entity->thongtin);
        $db->set_string_params("IsDeleted", $entity->isdeleted);
        return $db->excute();
    }

    public static function get_all() {
        $db = new dbhelper();
        $query = "SELECT * FROM SanPham";
        $db->setQuery($query);
        $result = $db->excute();
        $entity_arr = array();
        $index = 0;
        while ($row = mysql_fetch_array($result)) {
            $entity = new sanpham();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->gia = $row['Gia'];
            $entity->loaisanpham = $row['LoaiSanPham'];
            $entity->hinhanh = $row['HinhAnh'];
            $entity->thongtin = $row['ThongTin'];
            $entity->isdeleted = $row['IsDeleted'];
            $entity_arr[$index] = $entity;
            $index = $index + 1;
        }
        return $entity_arr;
    }

    public static function get(&$entity) {
        $db = new dbhelper();
        $query = "SELECT * FROM SanPham WHERE Id = #Id#";
        $db->setQuery($query);
        $db->set_string_params("Id", $entity->id);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new sanpham();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->gia = $row['Gia'];
            $entity->loaisanpham = $row['LoaiSanPham'];
            $entity->hinhanh = $row['HinhAnh'];
            $entity->thongtin = $row['ThongTin'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_id($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM SanPham WHERE id = #id#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new sanpham();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->gia = $row['Gia'];
            $entity->loaisanpham = $row['LoaiSanPham'];
            $entity->hinhanh = $row['HinhAnh'];
            $entity->thongtin = $row['ThongTin'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_ten($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM SanPham WHERE ten = #ten#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new sanpham();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->gia = $row['Gia'];
            $entity->loaisanpham = $row['LoaiSanPham'];
            $entity->hinhanh = $row['HinhAnh'];
            $entity->thongtin = $row['ThongTin'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_gia($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM SanPham WHERE gia = #gia#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new sanpham();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->gia = $row['Gia'];
            $entity->loaisanpham = $row['LoaiSanPham'];
            $entity->hinhanh = $row['HinhAnh'];
            $entity->thongtin = $row['ThongTin'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_loaisanpham($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM SanPham WHERE loaisanpham = #loaisanpham#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new sanpham();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->gia = $row['Gia'];
            $entity->loaisanpham = $row['LoaiSanPham'];
            $entity->hinhanh = $row['HinhAnh'];
            $entity->thongtin = $row['ThongTin'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_hinhanh($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM SanPham WHERE hinhanh = #hinhanh#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new sanpham();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->gia = $row['Gia'];
            $entity->loaisanpham = $row['LoaiSanPham'];
            $entity->hinhanh = $row['HinhAnh'];
            $entity->thongtin = $row['ThongTin'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_thongtin($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM SanPham WHERE thongtin = #thongtin#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new sanpham();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->gia = $row['Gia'];
            $entity->loaisanpham = $row['LoaiSanPham'];
            $entity->hinhanh = $row['HinhAnh'];
            $entity->thongtin = $row['ThongTin'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_isdeleted($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM SanPham WHERE isdeleted = #isdeleted#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new sanpham();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->gia = $row['Gia'];
            $entity->loaisanpham = $row['LoaiSanPham'];
            $entity->hinhanh = $row['HinhAnh'];
            $entity->thongtin = $row['ThongTin'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_post_data() {
        $entity = new sanpham();
        $entity->id = $_POST["id"];
        $entity->ten = $_POST["ten"];
        $entity->gia = $_POST["gia"];
        $entity->loaisanpham = $_POST["loaisanpham"];
        $entity->hinhanh = $_POST["hinhanh"];
        $entity->thongtin = $_POST["thongtin"];
        $entity->isdeleted = $_POST["isdeleted"];
        return $entity;
    }

    public static function search($search_key) {
        $arr = explode(" ", trim($search_key));
        $search = "";
        for ($i = 0; $i < count($arr); $i++) {
            if ($search == "") {
                $search = $search . " WHERE ";
                $search = $search . "(";
                $search = $search . "id LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || ten LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || gia LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || loaisanpham LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || hinhanh LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || thongtin LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || isdeleted LIKE '%" . $arr[$i] . "%'";
                $search = $search . ")";
            } else {
                $search = $search . " AND ";
                $search = $search . "(";
                $search = $search . "id LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || ten LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || gia LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || loaisanpham LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || hinhanh LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || thongtin LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || isdeleted LIKE '%" . $arr[$i] . "%'";
                $search = $search . ")";
            }
            $db = new dbhelper();
            $query = "SELECT * FROM SanPham" . $search;
            $db->setQuery($query);
            $result = $db->excute();
            $entity_arr = array();
            $index = 0;
            while ($row = mysql_fetch_array($result)) {
                $entity = new sanpham();
                $entity->id = $row['Id'];
                $entity->ten = $row['Ten'];
                $entity->gia = $row['Gia'];
                $entity->loaisanpham = $row['LoaiSanPham'];
                $entity->hinhanh = $row['HinhAnh'];
                $entity->thongtin = $row['ThongTin'];
                $entity->isdeleted = $row['IsDeleted'];
                $entity_arr[$index] = $entity;
                $index = $index + 1;
            }
            return $entity_arr;
        }
    }

}

?>